//
//  YQIncubatorHomePageVC.m
//  NewRetail
//
//  Created by yuqin on 2019/6/30.
//  Copyright © 2019 yuqin. All rights reserved.
//

#import "YQIncubatorHomePageVC.h"
#import "YQIncubatorVC.h"
#import "YQIncubatorProjectBottomView.h"
#import "YQHomePageHeadView.h"
#import "YQIncubatorHomeCell.h"

@interface YQIncubatorHomePageVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) YQIncubatorProjectBottomView *bottomView;
@property (nonatomic, strong) UIButton *headBtn;
@property (nonatomic, strong) YQHomePageHeadView *headImgView;
@property (nonatomic, strong) UITableView *homeTableView;
@property (nonatomic, strong) UIButton *getShareBtn;//领取分享收益

@end

@implementation YQIncubatorHomePageVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.txtTitle.text = @"首页";
    self.view.backgroundColor = LineColor;
    
    //设置UI
    [self setupView];
    
}

- (void)setupView {
    
    [self.view addSubview:self.bottomView];
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-Botoom_IPhoneX);
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(ScreenWidth, FIT(54)));
    }];
    
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, NavigationStatusBarHeight, ScreenWidth, FIT(50))];
    backView.backgroundColor = WhiteColor;
    [self.view addSubview:backView];
    
    UIImageView *img = [YQViewFactory imageViewWithImage:YQ_IMAGE(@"laba")];
    img.frame = CGRectMake(kMargin_left, kMargin_top, FIT(21), FIT(18));
    [backView addSubview:img];
    
    UIButton *titleBtn = [YQViewFactory buttonWithTitle:@"孵化器最新资讯请关注公众号" titleColor:MainBlueColor fontSize:kNormalButtonFont userBold:NO target:self sel:@selector(openNotiAction)];
    [backView addSubview:titleBtn];
    [titleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(img.mas_right).mas_equalTo(FIT(10));
        make.centerY.mas_equalTo(img.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(FIT(200), FIT(14)));
    }];
    
    //headView
    [self.view addSubview:self.headImgView];
    [self.headImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(kMargin_left);
        make.top.equalTo(backView.mas_bottom).mas_equalTo(kMargin_top);
        make.size.mas_equalTo(CGSizeMake(ScreenWidth-2*kMargin_left, FIT(230)));
    }];
    
    //tableView
    [self.view addSubview:self.homeTableView];
    [self.homeTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.equalTo(self.headImgView.mas_bottom).mas_equalTo(FIT(40));
        make.size.mas_equalTo(CGSizeMake(ScreenWidth, FIT(130)));
    }];
    
    [self.view addSubview:self.getShareBtn];
    [self.getShareBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headImgView.mas_bottom).mas_equalTo(-FIT(24));
        make.centerX.mas_equalTo(self.headImgView.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(FIT(167), FIT(48)));
    }];
    
}

- (void)openNotiAction {
    
}

- (YQIncubatorProjectBottomView *)bottomView {
    if (!_bottomView) {
        _bottomView = [[YQIncubatorProjectBottomView alloc] init];
        _bottomView.homePageBtn.selected = YES;
        @weakify(self);
        _bottomView.SwitchCtlBlock = ^(NSInteger tag) {
            @strongify(self);
            if (tag == 100) {
                
            }else {
                YQ_PUSH([YQIncubatorVC new]);
            }
        };
    }
    return _bottomView;
}

- (YQHomePageHeadView *)headImgView {
    if (!_headImgView) {
        _headImgView = [[YQHomePageHeadView alloc] init];
    }
    return _headImgView;
}

- (UITableView *)homeTableView {
    if (!_homeTableView) {
        _homeTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _homeTableView.backgroundColor = LineColor;
        _homeTableView.delegate = self;
        _homeTableView.dataSource = self;
        [_homeTableView registerClass:[YQIncubatorHomeCell class] forCellReuseIdentifier:YQ_incubator_HomePageCell];
        _homeTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _homeTableView;
}

- (UIButton *)getShareBtn {
    if (!_getShareBtn) {
        _getShareBtn = [YQViewFactory buttonWithTitle:@"领取分享收益" titleColor:MainBlueColor fontSize:FIT(15) userBold:YES target:self sel:@selector(getShareAction)];
//        [_getShareBtn setBackgroundImage:YQ_IMAGE(@"back_white") forState:UIControlStateNormal];
        [_getShareBtn setBackgroundColor:UIColorFromRGB(0xf5f5f5)];
        _getShareBtn.layer.cornerRadius = FIT(24);
    }
    return _getShareBtn;
}

//领取分享收益
- (void)getShareAction {
    
}

#pragma mark - 代理
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return FIT(130);
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    YQIncubatorHomeCell *cell = [tableView dequeueReusableCellWithIdentifier:YQ_incubator_HomePageCell forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}

@end
